#include "GameClass.h"

GameClass::GameClass()	{
	renderCounter	= 0.0f;
	physicsCounter	= 0.0f;

	physicsEnabled = true;

	exit = false;

	elapsedTime = 0;
}

GameClass::~GameClass(void)	{
	CleanUp();
	if(gameCamera) delete gameCamera;
	gameCamera= NULL;
}

void GameClass::CleanUp(){
	for(vector<GameEntity*>::iterator i = allEntities.begin(); i != allEntities.end(); ++i) {
		delete (*i);
	}
	allEntities.clear();
}

void GameClass::UpdateCore(float msec, bool physics) {
	elapsedTime += msec;

	renderCounter	-= msec;
	if(renderCounter <= 0.0f) {	//Update our rendering logic
		Renderer::GetRenderer().UpdateScene(1000.0f / (float)RENDER_HZ);
		Renderer::GetRenderer().RenderScene();
		renderCounter += (1000.0f / (float)RENDER_HZ);
	}

	//So physics can be paused, but renderring can still take place...pause menu
	if(physicsEnabled && physics){
		physicsCounter	+= msec;
		while(physicsCounter >= 0.0f) {
			physicsCounter -= PHYSICS_TIMESTEP;
			PhysicsSystem::GetPhysicsSystem().Update(PHYSICS_TIMESTEP);
		}
	}
}